﻿
         function GetInterpreter(text, div, slid)
         {
             //Encode text first
             text = text.replace(",", "##zap##");
            
            
            Silverlight.createObject(
            "fpinterpreter.xap",  // source
            div,  // parent element
            slid,  // id for generated object element
            {
            width: "400", height: "300", background: "white",
            version: "2.0.31005.0"
        }, //plugin properties
        { onError: onSilverlightError }, //events
            "initialCode = {code}".replace("{code}", text) //custom properties
            ,
            "context"    // context helper for onLoad handler.

        );

        function onSilverlightError(sender, args) {
            var appSource = "";
            if (sender != null && sender != 0) {
                appSource = sender.getHost().Source;
            }
            var errorType = args.ErrorType;

            var iErrorCode = args.ErrorCode;
            var errMsg = "Unhandled Error in Silverlight 2 Application " + appSource + "\n";
            errMsg += "Code: " + iErrorCode + "    \n";
            errMsg += "Category: " + errorType + "       \n";
            errMsg += "Message: " + args.ErrorMessage + "     \n";
            if (errorType == "ParserError") {
                errMsg += "File: " + args.xamlFile + "     \n"; errMsg += "Line: " + args.lineNumber + "     \n";
                errMsg += "Position: " + args.charPosition + "     \n";
            }
            else
                if (errorType == "RuntimeError") {
                if (args.lineNumber != 0) {
                    errMsg += "Line: " + args.lineNumber + "     \n";
                    errMsg += "Position: " + args.charPosition + "     \n";
                }
                errMsg += "MethodName: " + args.methodName + "     \n";
            }
            throw new Error(errMsg);
        } 
        
        
        
        }
